/*********************************************************
 *
 * Filename: ttest.c
 *   Author: jmdvirus
 *   Create: 2018年12月08日 星期六 12时01分42秒
 *
 *********************************************************/

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(int argc, char *args[]) {
	int fd, cnt;
	char buf[256] = {0};
	fd = open(args[1], O_RDWR);
	if (fd <= 0) {
		printf("Open file [%s] failed, [%s] \n", args[1], strerror(errno));
		return 1;
	}

    const char *writebuf = "this is a test to kernel";
	cnt = write(fd, writebuf, strlen(writebuf));
	if (cnt == 0) {
		printf("write failed\n");
	}

	cnt = read(fd, buf, 256);
	if (cnt == 0) {
		printf("read failed\n");
	}

	printf("read out data [%s]\n", buf);
	return 0;
}

